﻿// // ******************************************************************
// //       /\ /|       @file       SubtitleRepository.cs
// //       \ V/        @brief      await29
// //       | "")       @author     Await, 285283010@qq.com
// //       /  |
// //      /  \\        @Modified   2024-12-31 20:12
// //    *(__\_\        @Copyright  Copyright (c) , 2024-12-27 18:12 Await
// // ******************************************************************

using AutomaticSubtitles.Service.DataAccess.Model;
using AutomaticSubtitles.Service.Domain.Media;

namespace AutomaticSubtitles.Service.Infrastructure.Repositories;

public class SubtitleRepository(AutoDbContext context, IUnitOfWork unitOfWork, IStringLocalizer<SharedResource> localizer) : BaseRepository<AutoDbContext, Auto_Subtitle, string>
    (context, unitOfWork, localizer), ISubtitleRepository
{
    public async Task AddRange(List<Auto_Subtitle> newSubtitles)
    {
        if (newSubtitles is { Count: 0 }) return;
        await Context.AddRangeAsync(newSubtitles);
        await Context.SaveChangesAsync();
    }

    public async Task UpdateRange(List<Auto_Subtitle> updatedSubtitles)
    {
        if (updatedSubtitles is { Count: 0 }) return;

        Context.UpdateRange(updatedSubtitles);
        await Context.SaveChangesAsync();
    }

    public async Task RemoveRange(List<Auto_Subtitle> deletedSubtitles)
    {
        if (deletedSubtitles is { Count: 0 }) return;
        Context.ChangeTracker.Clear();
        Context.RemoveRange(deletedSubtitles);
        await Context.SaveChangesAsync();
    }

    public Task<List<Auto_Subtitle>> GetList()
    {
        return Context.AutoSubtitles.Where(x => true).AsNoTracking().ToListAsync();
    }
}